<template>
  <div class="mainua">
    <div class="main_spac1" style="padding-bottom: 5px">
      <div class="main_white padding10">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>满减满赠</span>
          </div>
        </div>
        <!-- 主要部分 -->
        <div class="marginTop10">
          <mf-reduce-edit
            v-if="form.type == 1"
            :data_form="form"
            :addtype="addtype"
            ref="marketingFullReduce"
          ></mf-reduce-edit>
          <mf-plus-edit
            v-if="form.type == 2"
            ref="marketingFullPlus"
            :data_form="form"
            :addtype="addtype"
          ></mf-plus-edit>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import mfPlusEdit from "./marketingFullEdit/mf_plus_edit.vue";
import mfReduceEdit from "./marketingFullEdit/mf_reduce_edit.vue";
export default {
  components: { mfPlusEdit, mfReduceEdit },
  data() {
    return {
      form: {
        type: "",
        id: "",
      },
      addtype: "",
    };
  },
  created() {
    this.form.type = this.$route.params.type;
    this.form.id = this.$route.params.id;
    if (this.$route.query.type) {
      this.addtype = this.$route.query.type;
    }
  },
  beforeRouteLeave(to, from, next) {
    let reduce_isEdit = "";
    let plus_isEdit = "";
    if (this.$refs["marketingFullReduce"]) {
      reduce_isEdit = this.$refs["marketingFullReduce"].isEdit;
    }
    if (this.$refs["marketingFullPlus"]) {
      plus_isEdit = this.$refs["marketingFullPlus"].isEdit;
    }

    if (reduce_isEdit || plus_isEdit) {
      setTimeout(() => {
        this.$confirm(
          "您已经有数据操作，离开页面系统不会保存您的操作，确定离开吗？",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            next();
          })
          .catch(() => {
            next(false);
          });
      }, 200);
    } else {
      next();
    }
  },
};
</script>



